/*
 * @Description: 静态配置文件
 * @Author: your name
 * @version:
 * @Date: 2023-12-19 09:11:15
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-05-19 14:38:23
 */


import * as Cesium from 'cesium'
import {circle} from '@turf/turf'
import data from '@/shader/index'
import {addFlyLines,addConeGlow,addMarkBuild,addFence,addWaveRing,addEchartsLayer} from '@/cesiumTools/sceneManager'

const {nightfs,moveRingShader,scanfs,rainfs,snowfs,fogFs}=data
console.log(rainfs)

// 天空盒子数据
export const skyBoxData = () => {
  let data = [
    {
      title: "黄昏",
      key: "01",
      pic: "/src/assets/skyBox/01/pz.jpg",
    },
    {
      title: "清晨",
      key: "02",
      pic: "/src/assets/skyBox/02/pz.jpg",
    },
    {
      title: "中午",
      key: "03",
      pic: "/src/assets/skyBox/03/pz.jpg",
    },
    {
      title: "夜晚",
      key: "04",
      pic: "/src/assets/skyBox/04/pz.jpg",
    },
    {
      title: "傍晚",
      key: "05",
      pic: "/src/assets/skyBox/05/pz.jpg",
    },
  ];

  return data.map((item) => {
    const sources = {
      positiveX: `/src/assets/skyBox/${item.key}/px.jpg`,
      negativeX: `/src/assets/skyBox/${item.key}/nx.jpg`,
      positiveY: `/src/assets/skyBox/${item.key}/py.jpg`,
      negativeY: `/src/assets/skyBox/${item.key}/ny.jpg`,
      positiveZ: `/src/assets/skyBox/${item.key}/pz.jpg`,
      negativeZ: `/src/assets/skyBox/${item.key}/nz.jpg`,
    };
    return {
      ...item,
      sources,
    };
  });
};

// 白膜特效选项
export const sceneOptions = [
  {
    label: "泛光",
    value: "泛光",
    fragmentShader: moveRingShader.fragmentShader,
    vetrixShader: moveRingShader.vetrixShader,
  },
  {
    label: "扫描光带",
    value: "扫描光带",
    fragmentShader: scanfs.fragmentShader,
    vetrixShader: scanfs.vetrixShader,
  },
  {
    label: "呼吸灯",
    value: "呼吸灯",
    // fragmentShader: mixShader.fragmentShader,
    // vetrixShader: mixShader.vetrixShader,
  },
  {
    label: "夜景",
    value: "夜景",
    fragmentShader: nightfs.fragmentShader,
    vetrixShader: nightfs.vetrixShader,
  },
  {
    label: "无效果",
    value: "无效果",
    fragmentShader: null,
    vetrixShader: null,
  },
];

// 道路效果选项
export const roadOptions = [
  {
    label: "道路流线",
    value: "flow",
    dataSource: "/src/assets/road2.json",
  },
  {
    label: "道路泛光",
    value: "bink",
    dataSource: "/src/assets/road.json",
  },
  {
    label: "无效果",
    value: "none",
    dataSource: null,
  },
];

// 天气选项
export const climateOptions = [
  {
    label: "雨天",
    value: "rain",
    fs: rainfs.fragmentShader,
  },
  {
    label: "雪天",
    value: "snow",
    fs: snowfs,
  },
  {
    label: "雾天",
    value: "frag",
    fs: fogFs,
  },
  {
    label: "晴天",
    value: "none",
    fs: null,
  },
];

// 工具栏
export const toolsOptions = [
  {
    label: "地图量测",
    value: "measure",
  },
  {
    label: "地图绘制",
    value: "draw",
  },
  {
    label: "地形开挖",
    value: "dynacut",
  },
  {
    label: "底图滤镜",
    value: "baseMapFilter",
  },
  {
    label: "天空切换",
    value: "skySwitch",
  },
];

// 城市特效选项
export const cityEffectOptions = [
  {
    label: "全图飞线",
    value: "全图飞线",
    rendered: false,
    addMethod:(viewer)=>{
      const {centerPoint}=cityEffectData()
      addFlyLines(centerPoint,300,5000,5,
        new Cesium.Color(158/255, 199/255, 16/255, 0.8),viewer)
    },
    removeMethod:()=>{
      
    }
  },{
    label: "光锥标识",
    value: "光锥标识",
    addMethod: (viewer) => {
      const { conePositions } = cityEffectData();
      conePositions.forEach((position) => {
        addConeGlow({
          lng:position[0],
          lat:position[1],
          height:1000
        }, 2000, 120, Cesium.Color.fromRandom(), viewer);
      });
    }
  },{
    label: "地标建筑",
    value: "地标建筑",
    addMethod:(viewer)=>{
      const {centerPoint: { lng, lat }} = cityEffectData();
      const position={lng, lat,height:520}
      addMarkBuild(position,viewer);
      const option={
        wallColor:Cesium.Color.ORANGERED,
        wallHeight:1000
      }
      // 添加电子围栏
      addFence(position,option,viewer)
    }
  },{
    label: "重要地点",
    value: "重要地点",
    addMethod:(viewer)=>{
      const position={lng:104.06761545792156,lat:30.663060741759804,height:500}
      addWaveRing(position,500,Cesium.Color.ORANGE,viewer)
    }
  },{
    label: "echarts图层",
    value: "echarts图层",
    addMethod:(viewer)=>{
      const {echartsPoints}=cityEffectData()
      addEchartsLayer(viewer,echartsPoints)
    }
  }
];


// 特殊效果所需要的坐标数据
export const cityEffectData = () => {
  // 市中心坐标
  const centerPoint = {
    lng: 104.0656,
    lat: 30.6582,
  };

  //   重要建筑坐标
  const waterPoint = [104.08708978256001, 30.617128698331488];
  const communityPoint = [104.11289261051867, 30.65220697441596];
  const waterPosition = Cesium.Cartesian3.fromDegrees(
    waterPoint[0],
    waterPoint[1],
    30
  );
  const communityPosition = Cesium.Cartesian3.fromDegrees(
    communityPoint[0],
    communityPoint[1],
    30
  );
  //   市中心抛物线坐标
  const startPosition = Cesium.Cartesian3.fromDegrees(
    centerPoint.lng,
    centerPoint.lat,
    0
  );
  const circlePoints = circle([centerPoint.lng, centerPoint.lat], 4, {
    steps: 10,
    units: "kilometers",
    properties: { foo: "bar" },
  });
  //   市中心终点坐标
  const endPositions = circlePoints.geometry.coordinates[0].map((point) => {
    const resPosition = Cesium.Cartesian3.fromDegrees(point[0], point[1], 0);
    return resPosition;
  });
  //   echarts图层坐标
  const echartsPoints = [
    [104.06761545792156, 30.663060741759804],
    [104.14832743101942, 30.631395838248544],
    [104.16403985356958, 30.677576160573658],
    [104.14905206947572, 30.729124321282193],
    [104.09080607569864, 30.754636449322316],
    [104.02947899298753, 30.74507686495438],
    [103.97848046512556, 30.70247957862805],
    [103.96722972635733, 30.62643534075023],
    [104.0334959508809, 30.59837817371358],
    [104.08010037851007, 30.582097737255307],
  ];

  const conePositions = [
    [104.0684460104926, 30.66014193327171],
    [104.0689161226566, 30.634866996443783],
    [104.09733539196452, 30.64968629062517],
    [104.03733993145981, 30.64956805226576],
    [104.0666120102447, 30.696779896565477],
  ];

  //   城市特殊效果选项
  const cityEffectOptions = [
    {
      label: "全图飞线",
      value: "全图飞线",
      rendered: false,
    },
    {
      label: "光锥标识",
      value: "光锥标识",
      rendered: false,
    },
    {
      label: "市中心特效",
      value: "市中心特效",
      rendered: false,
    },
    {
      label: "重要建筑效果",
      value: "重要建筑效果",
      rendered: false,
    },
    {
      label: "echarts图层",
      value: "echarts图层",
      rendered: false,
    },
    {
      label: "水域效果",
      value: "水域效果",
      rendered: false,
    },
  ];

  return {
    centerPoint,
    endPositions,
    startPosition,
    communityPosition,
    waterPosition,
    echartsPoints,
    cityEffectOptions,
    conePositions
  };
};

export const modelUrls = ["http://localhost:8888/chengdu/tileset.json",'http://localhost:8888/model/b3dm/tileset.json'];
